﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SmartSpace.Core;

namespace SsTool.Common
{
    /// <summary>
    /// Interaction logic for SelectViewWindow.xaml
    /// </summary>
    public partial class SelectViewWindow : Window
    {
        public ModuleView SelectedView { get; private set; }

        public SelectViewWindow()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(ModuleListPage_Loaded);
        }

        void ModuleListPage_Loaded(object sender, RoutedEventArgs e)
        {
            LoadDatas();
        }

        private void LoadDatas()
        {
            ICoreService service = App.Get<ICoreService>();
            List<Module> modules = service.GetModules(0, 999);
            _ctlGridModules.ItemsSource = modules;
        }

        private void _ctlGridModules_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            Module selectedModule = _ctlGridModules.SelectedItem as Module;
            if (selectedModule == null)
            {
                _ctlGridViews.ItemsSource = null;
            }
            else
            {
                _ctlGridViews.ItemsSource = selectedModule.Views;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SelectedView = _ctlGridViews.SelectedItem as ModuleView;
            if (SelectedView != null)
            {
                DialogResult = true;
            }
        }

        private void _ctlBtnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
